package spring.core.examples.xml;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

/**
 * Demonstrates how to write a publisher.
 * 
 * @see Subscriber
 * @see Event
 */
public class Publisher implements ApplicationEventPublisherAware {

	/** The publisher. */
	private ApplicationEventPublisher publisher;

	/**
	 * Publish.
	 * 
	 * @param message
	 *            the message
	 */
	public void publish(String message) {
		Event myEvent = new Event(this, message);
		System.out.println("Sende: " + myEvent);
		this.publisher.publishEvent(myEvent);
		System.out.println("Fertig mit senden: " + myEvent);
	}

	/**
	 * 
	 * @see org.springframework.context.ApplicationEventPublisherAware#
	 *      setApplicationEventPublisher
	 *      (org.springframework.context.ApplicationEventPublisher)
	 */
	public void setApplicationEventPublisher(
			ApplicationEventPublisher applicationEventPublisher) {
		this.publisher = applicationEventPublisher;
	}

}
